/*******************************************************************************
 * Copyright (c) 2009-2011 ETCORE Labs. All rights reserved. 
 * 
 * This software is the confidential and proprietary information of ETCORE Labs.
 * You shall not disclose such confidential information and shall use it
 * only in accordance with the terms of the license agreement you entered into
 * with ETCORE Labs. 
 * 
 * Support can be obtained from support forums at:  http://www.etcore.com/
 * /
 *******************************************************************************/
package etcore.webapp.grouptalk.common.action;

import java.util.List;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import etcore.webapp.grouptalk.util.SearchUtil;

public class SearchServlet extends HttpServlet {

 
	private static final long serialVersionUID = -7774631562868852500L;

	public void service(HttpServletRequest request, HttpServletResponse response)
			throws java.io.IOException {

		String key = request.getParameter("key");
		if (key != null)
			key = new String(key.getBytes("ISO-8859-1"), "gb2312");
		@SuppressWarnings("rawtypes")
		List result = SearchUtil.getKeywords(key);

		StringBuffer stringBuffer = new StringBuffer();
		if (result != null && result.size() > 0) {
			for (int i = 0; i < result.size(); i++) {
				Object[] gk = (Object[]) result.get(i);
				stringBuffer.append((String) gk[0]);
				stringBuffer.append("|");

			}
		}
		response.setCharacterEncoding("gb2312");
		response.setContentType("text/html;   charset=gb2312");
		response.getWriter().write(stringBuffer.toString());

		// Write XML to response.
		// res.setContentType("application/xml");

	}

}
